#include "btform.h"
#include "ui_btform.h"
BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);
    //ui->lineBox->hide();
    this->hideAnimation();
    setLineAnimation(ui->line1,1500,0,7,2,20);
    setLineAnimation(ui->line2,1600,7,7,2,20);
    setLineAnimation(ui->line3,1700,14,7,2,20);
    setLineAnimation(ui->line4,1800,21,7,2,20);

}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::seticon(QString btIcon, QString content, int mid)
{
    // 设置自定义按钮的图片、文字、以及id
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(content);
    this->id = mid;
}

int BtForm::getId()
{
    return this->id;
}

void BtForm::clearBackground()
{
    // 鼠标点击之后，背景变为绿色，文字变为白色
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void BtForm::setLineAnimation(QWidget *target, int duration, int x, int y, int width, int height)
{
    QPropertyAnimation* anim = new QPropertyAnimation(target, "geometry", this);
    anim->setDuration(duration);
    anim->setKeyValueAt(0, QRect(x, height, width, 0));
    anim->setKeyValueAt(0.5, QRect(x, y, width, height));
    anim->setKeyValueAt(1, QRect(x, height, width, 0));
    anim->setLoopCount(-1);
    anim->start();
}

void BtForm::showAnimation()
{
    ui->line1->show();
    ui->line2->show();
    ui->line3->show();
    ui->line4->show();
}

void BtForm::hideAnimation()
{
    ui->line1->hide();
    ui->line2->hide();
    ui->line3->hide();
    ui->line4->hide();
}

void BtForm::setSelected(int id)
{
    // 鼠标点击之后，背景变为蓝色，文字变为白色
    ui->btStyle->setStyleSheet("#btStyle{ background:rgb(0,153,255);}*{color:#F6F6F6;}");
    emit btClick(this->id); // 发送鼠标点击信号
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    // 告诉编译器不要触发警告
    (void)event;
    // 鼠标点击之后，背景变为蓝色，文字变为白色
    ui->btStyle->setStyleSheet("#btStyle{ background:rgb(0,153,255);}*{color:#F6F6F6;}");
    emit btClick(this->id); // 发送鼠标点击信号
}
